package com.hq.fxh.No5_User.User.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hq.fxh.Modle.GetEntertainmentListResInfo;
import com.hq.fxh.Modle.GetMyPostModle;
import com.hq.fxh.Modle.GetVideoListModle;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.Tool;

import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;

import static android.R.attr.data;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/15
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_MyVideo extends BaseAdapter {
    List<GetVideoListModle.DataBean> data;
    OnDeleteCallBack onDeleteCallBack;
    String name = "Radapter_UserSpace_Plate";

    public void setData( List<GetVideoListModle.DataBean> data) {
        this.data = data;
    }

    public void setOnDeleteCallBack(OnDeleteCallBack onDeleteCallBack) {
        this.onDeleteCallBack = onDeleteCallBack;
    }


    @Override
    public int getCount() {
        return data == null ?  0 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_myplate_video, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (data != null && data.size() > position) {
            GetVideoListModle.DataBean dataBean = data.get(position);

            Tool.setIntToText(viewHolder.videoFragmentNum, dataBean.getAction_num(), "Ladapter_MyVideo");
            Tool.setStringToText(viewHolder.videoFragmentVideoName, dataBean.getSubject_title());
            Tool.setStringToText(viewHolder.videoFragmentTime, dataBean.getSubject_item_count());
            Tool.setUrlToImage1(parent.getContext(), dataBean.getSubject_img_url(), viewHolder.videoListImage);
            Tool.setImageBG(parent.getContext(), dataBean.getSubject_img_url(), viewHolder.videoListImageBg);
        }else {
            Tool.setUrlToImage(parent.getContext(), AppConstant.imageUrl, viewHolder.videoListImage);

        }


        viewHolder.btnDeleteVideo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onDeleteCallBack.deleteCall(position, null);
            }
        });

        return view;
    }


    public interface OnDeleteCallBack {
        void deleteCall(int position, GetEntertainmentListResInfo data);
    }

    static class ViewHolder {
        protected TextView videoFragmentVideoName;
        protected ImageView videoListImageBg;
        protected ImageView videoListImage;
        protected TextView videoFragmentNum;
        protected TextView videoFragmentTime;
        protected TextView btnDeleteVideo;
        protected LinearLayout layoutDeleteVideo;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            videoFragmentVideoName = (TextView) rootView.findViewById(R.id.videoFragment_videoName);
            videoListImageBg = (ImageView) rootView.findViewById(R.id.videoList_Image_bg);
            videoListImage = (ImageView) rootView.findViewById(R.id.videoList_Image);
            videoFragmentNum = (TextView) rootView.findViewById(R.id.videoFragment_Num);
            videoFragmentTime = (TextView) rootView.findViewById(R.id.videoFragment_Time);
            btnDeleteVideo = (TextView) rootView.findViewById(R.id.btn_delete_video);
            layoutDeleteVideo = (LinearLayout) rootView.findViewById(R.id.layout_delete_video);
            layoutDeleteVideo.setVisibility(View.VISIBLE);
        }
    }
}
